package it.bsoft.gameboy.memory;

import it.bsoft.bin.util.UShort;

public class ShortSplittableRegister {

	private final ByteRegister lowRegister = new ByteRegister();
	private final ByteRegister highRegister = new ByteRegister();
	
	public UShort getValue(){
		long highValue = (highRegister.getValue().shortValue())<<8;
		long lowValue = lowRegister.getValue().shortValue();
		return UShort.fromLong(highValue|lowValue);
	}
	
	
	public void setValue(long value){
		setValue(UShort.fromLong(value));
	}
	
	public void setValue(UShort value){
		long highValue = (value.intValue()&0xFF00)>>8;
		long lowValue = value.intValue()&0xFF;
		
		this.lowRegister.setValue(lowValue);
		this.highRegister.setValue(highValue);
	}
	
	public ByteRegister getLowRegister(){
		return this.lowRegister;
	}
	
	public ByteRegister getHighRegister(){
		return this.highRegister;
	}
	
	
	public void clear(){
		this.lowRegister.clear();
		this.highRegister.clear();
	}
	
}
